//
//  ZYStatusToolBar.swift
//  weiboZY
//
//  Created by 赵勇 on 16/5/14.
//  Copyright © 2016年 赵勇. All rights reserved.
//

import UIKit
// 微博底部toolbar
class ZYStatusToolBar: UIView {

    // 转发按钮
    private lazy var retWeetButon:UIButton = self.addChildButton("转发", imageName:"timeline_icon_retweet")
    // 评论按钮
    private lazy var commentBUtton:UIButton = self.addChildButton("评论", imageName:"timeline_icon_comment")
    // 赞按钮
    private lazy var unlikeBUtton:UIButton = self.addChildButton("赞", imageName:"timeline_icon_unlike")
    var statusViewModel: ZYStatusViewModel? {
        didSet{
            retWeetButon.setTitle(statusViewModel?.retweetCountContent, forState: .Normal)
            commentBUtton.setTitle(statusViewModel?.commentCountContent, forState: .Normal)
            unlikeBUtton.setTitle(statusViewModel?.unlikeCountContent, forState: .Normal)
        }
        
    }
// 创建控件
    override init(frame: CGRect) {
        super.init(frame: frame)
        setUpUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setUpUI() {
        // 添加竖线
        let firstLineView = addChildLineView()
        let secondLineView = addChildLineView()
        
    // 设置约束
        retWeetButon.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self)
            make.leading.equalTo(self)
            make.bottom.equalTo(self)
            make.width.equalTo(commentBUtton.snp_width)
        }
        commentBUtton.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self)
            make.leading.equalTo(retWeetButon.snp_trailing)
            make.bottom.equalTo(self)
            make.width.equalTo(unlikeBUtton)
        }
        unlikeBUtton.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self)
            make.leading.equalTo(commentBUtton.snp_trailing)
            make.bottom.equalTo(self)
            make.trailing.equalTo(self)
            make.width.equalTo(retWeetButon)
        }
        firstLineView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(retWeetButon.snp_trailing)
            make.centerY.equalTo(self)
        }
        secondLineView.snp_makeConstraints { (make) -> Void in
            make.centerY.equalTo(self)
            make.centerX.equalTo(commentBUtton.snp_trailing)
        }
    
    }
    
    // 创建子视图按钮
    private func addChildButton(title:String, imageName:String) -> UIButton {
        
        let button = UIButton()
        button.setTitle(title, forState: .Normal)
        button.setTitleColor(UIColor.grayColor(), forState: .Normal)
        button.setImage(UIImage(named: imageName), forState: .Normal)
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: .Normal)
        // 去掉按钮的点击效果
        button.adjustsImageWhenHighlighted = false
        button.titleLabel?.font = UIFont.systemFontOfSize(15)
        addSubview(button)
        return button
    }
    // 创建线
    private func addChildLineView() -> UIView {
        let view = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        addSubview(view)
        return view
    }
}





